package com.aaa.controller.xg;

import com.aaa.pojo.PlanFpa;

import com.aaa.pojo.ResultBean;
import com.aaa.service.xg.PlanFpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/planFpa")
public class PlanFpaController {
    @Autowired
    private PlanFpaService planFpaService;

    @RequestMapping("/pagination")
    public ResultBean planFpa( String page, String limit){
        int count = planFpaService.findCount();
        List<PlanFpa> data = planFpaService.findAll(page, limit);

        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setCount(count);
        resultBean.setMsg("");
        resultBean.setData(data);
        return  resultBean;

    }


    @RequestMapping("/insert")
    public ResultBean save(@RequestBody PlanFpa planFpa){
        //System.out.println(planFpa);
        planFpa.setTestCode((int) ((Math.random() * 9 + 1) * 100000));
        planFpa.setCreateTime(new Date());

        int insert = planFpaService.insert(planFpa);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        return resultBean;
    }

    @RequestMapping("/update")
    public ResultBean update(@RequestBody PlanFpa planFpa){

        //planFpa.setTestCode((int) ((Math.random() * 9 + 1) * 100000));
        planFpa.setUpdateTime(new Date());
        planFpaService.update(planFpa);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        return resultBean;

    }

    @RequestMapping("/findByIf")
    public ResultBean findByIf(String testName,String createBy){

        List<PlanFpa> planFpaList = planFpaService.findByName(testName, createBy);
        int ifCount = planFpaService.findIfCount(testName, createBy);
        ResultBean resultBean = new ResultBean();
        resultBean.setCount(ifCount);
        resultBean.setCode(0);
        resultBean.setData(planFpaList);
        resultBean.setMsg("");
        return resultBean;

    }

    @RequestMapping("/delete")
    public ResultBean delete(@RequestParam("idList") List<String> idList){

        //System.out.println(idList);
        int delete = planFpaService.delete(idList);
        //  System.out.println(delete);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        return resultBean;

    }
    @RequestMapping({"/toShowPlanFpa.do"})
    public ModelAndView toShowPlanFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("showPlanFpa");
        return modelAndView;
    }
    @RequestMapping({"/toShowQuestionFpa.do"})
    public ModelAndView toShowQuestionFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("showQuestionFpa");
        return modelAndView;
    }
    @RequestMapping({"/toshowResultFpa.do"})
    public ModelAndView toShowResultFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("showResultFpa");
        return modelAndView;
    }
    @RequestMapping({"/toFormsFpa.do"})
    public ModelAndView toFormsFpa(ModelAndView modelAndView) {
        modelAndView.setViewName("reportFormsFpa");
        return modelAndView;
    }

}
